package com.maker.LMMS.hook;

import com.blade.ioc.annotation.Bean;
import com.blade.mvc.RouteContext;
import com.blade.mvc.hook.WebHook;
import com.blade.mvc.http.Request;
import com.blade.mvc.http.Response;

/**
 * @author : zimu
 * @Date: 2018/7/31 20:35
 * @description :
 */

@Bean
public class AdminHook implements WebHook {
    @Override
    public boolean before(RouteContext signature) {
        Request request = signature.request();
        Response response = signature.response();
        String uri = request.uri();
        if(uri.indexOf("/backstage")==0&&!uri.equals("/backstage/signin")&&!uri.equals("/backstage/backstage_login"))
        {
            if (request.session().attribute("admin_name")==null) {
                response.redirect("/backstage/signin?uri="+uri);
                return false;
            }
        }
        System.out.println(request.method()+uri);
        return true;
    }
}
